<?php

namespace app\common\model;

use think\Model;
use think\Loader;
use think\Hook;
use Carbon\Carbon;
use think\Exception;
use app\common\traits\model\TraitModel;

class MeetWishUsers extends Model
{
	use TraitModel;

    protected $autoWriteTimestamp = 'timestamp';
    protected $createTime         = 'created_at';
    protected $updateTime         = 'updated_at';
    protected $table              = 'meet_wish_users';

    public function meet($caravan)
    {
    	if ($this->where(['wish_id' => $this->wish->id, 'meet_user_id' => $caravan->user_id, 'caravan_id' => $caravan->id])->count()) {
    		throw new Exception("I've got the order", 1);
    	}
    	return $this->create(['wish_id' => $this->wish->id, 'meet_user_id' => $caravan->user_id, 'caravan_id' => $caravan->id]);
    }

    public function getMeet($id)
    {
    	if ($meet_info = $this->get(['id' => $id])) {
    		return $meet_info;
    	}
    	throw new Exception("Receipt information does not exist", 1);
    }

    public function getMeets()
    {
    	return $this->where(['wish_id' => $this->wish->id])->select();
    }

    public function delMeets($ids = null)
    {
    	return $this->where(['wish_id' => $this->wish->id])->delete();
    }
}
